all: mdemon suspend resume send_sms pripoj closepppd closeopenvpn

# kam instalovat
INSTDIR = /usr/local/bin
ETCDIR = /usr/local/etc/mdemon
INSTAPL = /usr/local/bin/mdemonapl

mdemon: demon.c MessageToPDUMessage.h 
	gcc -o mdemon demon.c MessageToPDUMessage.h
suspend: suspend.c mdainicialization.h
	gcc -o suspend suspend.c mdainicialization.h
resume: resume.c mdainicialization.h
	gcc -o resume resume.c mdainicialization.h
send_sms: send_sms.c mdainicialization.h
	gcc -o send_sms send_sms.c mdainicialization.h
pripoj: pripoj.c ping.h closepppd.h
	gcc -o pripoj pripoj.c ping.h closepppd.h
closepppd: closepppd.c closepppd.h
	gcc -o closepppd closepppd.c closepppd.h
closeopenvpn: closeopenvpn.c
	gcc -o closeopenvpn closeopenvpn.c

install: all
	@mkdir -p $(INSTDIR); \
	mkdir -p $(ETCDIR); \
	mkdir -p $(INSTAPL); \
	mkdir -p /usr/share/man/SK 

	@if [ -d $(INSTDIR) ] && [ -d $(ETCDIR) ] && [ -d $(INSTAPL) ]; \
        then \
                cp mdemon $(INSTDIR);\
                chmod og+x $(INSTDIR)/mdemon;\
		cp suspend $(INSTAPL);\
		cp resume $(INSTAPL);\
		cp send_sms $(INSTAPL);\
		cp pripoj $(INSTAPL);\
		cp closeopenvpn $(INSTAPL);\
		cp closepppd $(INSTAPL);\
		cp mdemonusr.conf $(ETCDIR);\
		cp mdemonadr.conf $(ETCDIR);\
                cp mdemon.conf $(ETCDIR);\
		cp users.conf $(ETCDIR);\
		cp man/SK/mdemon.1 /usr/share/man/man1;\
		cp man/SK/mdemon.conf.5 /usr/share/man/man5;\
                echo "mdemon uspesne nainstalovany do $(INSTDIR) s konfiguracnym suborom mdemon.conf v $(ETCDIR)";\
        else \
                echo "instalacia do $(INSTDIR) a $(ETCDIR) sa nepodarila";\
        fi
